/*分页组件初始化*/
$(function () {
    var component = $('body').find('.page_navigation');
    var table = $('body').find('.page');
    var pageNum = component.data('pagenum');
    var pageSize = component.data('pagesize');
    var totalNum = component.data('totalnum');
    var totalPage = component.data('totalpage');

    //上一页
    $('.Previous').click(function () {
        if (isNaN(pageNum) || pageNum < 1) {
            return;
        } else {
            pageNum--;
            changePage(pageNum, pageSize, location.pathname, table);
        }
    });

    //下一页
    $('.Next').click(function () {
        if (isNaN(pageNum) || pageNum + 1 >= totalPage) {
            return;
        } else {
            pageNum++;
            changePage(pageNum, pageSize, location.pathname, table);
        }
    });

    //跳页
    $('.Jump').click(function () {
        jumpPage();
    });

    //输入框回车时间
    $("#inputPageNum").keydown(function (event) {
        if (event.keyCode == 13) {
            jumpPage();
        }
    });

    var changePage = function (pageNum, pageSize, url, table) {
        $.ajax({
            url: url,
            type: 'post',
            data: {
                pageNum: pageNum,
                pageSize: pageSize
            },
            success: function (result) {
                table.html(result);
                $(".Message").text("第" + (pageNum + 1) + "页，共" + totalPage + "页");
            }
        });
    }

    function jumpPage() {
        var inputPageNum = +$("#inputPageNum").val();
        if (isNaN(inputPageNum) || inputPageNum + 1 >= totalPage || inputPageNum < 1) {
            return;
        } else {
            pageNum = inputPageNum - 1;
            changePage(pageNum, pageSize, location.pathname, table);
        }
    }

});
